import 'package:flutter/material.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/in_order_page_detail_child_entity.dart';
import 'package:library_base/entities/in_order_page_entity.dart';
import 'package:library_base/ext/list_ext.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:library_base/widget/multi_state_widget/multi_state_widget.dart';
import 'package:library_base/base/base_list_state.dart';
import 'package:module_wms/page/incoming_orders/incoming_orders_detail/incoming_orders_detail_controller.dart';
import 'package:module_wms/page/incoming_orders/incoming_orders_detail/incoming_orders_detail_page_ui.dart';

class IncomingOrdersDetailPage extends StatefulWidget {
  const IncomingOrdersDetailPage({Key? key}) : super(key: key);

  @override
  _IncomingOrdersDetailPageState createState() => _IncomingOrdersDetailPageState();
}

class _IncomingOrdersDetailPageState extends BaseListState<InOrderPageDetailEntity,InOrderPageDetailChildEntity, IncomingOrdersDetailPage,
    IncomingOrdersDetailController> {
  @override
  IncomingOrdersDetailController registerController() => Get.put(IncomingOrdersDetailController());

  @override
  void onCreate() {
    super.onCreate();
    setTitle(MultiLanguage.detailsIncomingOrders.tr);
    setNavigationBarColor(ThemeUtil.getTheme().colorScheme.secondary);
  }

  @override
  void controllerOnCreate() {
    useRefresh = true;
    isCanRefresh = true;
    isCanLoad = false;
    enableControlFinishLoad = false;
    enableControlFinishRefresh = true;
    baseGetxController?.easyRefreshController = controller;
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return MultiStateWidget(
      emptyWidget: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            LocalImage('base_empty', package: Constant.packLib(), width: 0.6.sw),
            Text(MultiLanguage.noSuchProduct.tr, style: TextStyles.textSecondary28),
            SizedBox(height: 80.w),
            Row(mainAxisAlignment: MainAxisAlignment.center, children: [
              GradientButton(
                ThemeUtil.getTheme(),
                width: 0.4.sw,
                height: 80.w,
                text: MultiLanguage.reload.tr,
                onPressed: baseGetxController!.tryReLoad,
              ),
            ])
          ]),
      controller: baseGetxController!.multiControllerOut,
      buildChild: (){
        return Column(
          children: [
            Expanded(
              child:  Container(
                  color: ThemeUtil.getTheme().secondaryBgColor(),
                  child: getListView(context, baseGetxController)),
            ),
            buildBottom(
              baseGetxController!.totalCount,
              baseGetxController!.actualCount,
              baseGetxController!.enable,
              print:baseGetxController!.print,
              goodsFinish:baseGetxController!.goodsFinish,
            ),
          ],
        );
      },
      child: null,
    );
  }

  @override
  List<Widget> buildListItem(BuildContext context) {
    return baseGetxController!.listData.value.buildItem((index, element) {
      return buildItem(
        element,
        index,
        singleHeadEntry: baseGetxController!.singleHeadEntry,
        noSingleHeadEntry: baseGetxController!.noSingleHeadEntry,
      );
    }, dividingLine: () {
      return line2;
    });
  }


}
